package com.itheima.listener;

import com.itheima.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;


import javax.annotation.Resource;
import java.util.List;
@Component
public class StartupApplicationListener implements ApplicationListener<ContextRefreshedEvent> {

    @Resource
    private RedisTemplate<String,Object> redisTemplate;

    @Autowired(required = false)
    private List<BaseApplicationListener>listeners;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        RedisUtil.register(redisTemplate);
        //执行其他项目的监听器
        if (listeners!=null){
            listeners.stream().forEach(listeners->{
                listeners.onApplicationEvent(contextRefreshedEvent);
            });
        }
    }
}
